package com.kindsoft.demo.ldap;

import org.springframework.ldap.core.ContextMapper;
import org.springframework.ldap.core.DirContextAdapter;

import javax.naming.NamingException;

/**
 * Created by zhoujm on 2020/2/20/020.
 */
public class PersonMapper implements ContextMapper<Person> {
    public Person mapFromContext(Object ctx) throws NamingException {
        Person person = new Person();
        DirContextAdapter context = (DirContextAdapter)ctx;
        person.setCn(context.getStringAttribute("cn"));
        person.setCompany(context.getStringAttribute("company"));
        person.setDescription(context.getStringAttribute("description"));
        person.setGivenName(context.getStringAttribute("givenname"));
        person.setObjectClass(context.getStringAttribute("objectclass"));
        person.setSn(context.getStringAttribute("sn"));
        person.setSAMAccountName(context.getStringAttribute("samaccountname"));
        person.setUserAccountControl(context.getStringAttribute("useraccountcontrol"));
        person.setUserPrincipalName(context.getStringAttribute("userprincipalname"));
        person.setDn(context.getDn().toString());
        person.setDistinguishedName(context.getStringAttribute("distinguishedname"));
        return person;
    }
}
